﻿using System;
using System.Collections.Generic;

namespace AdaptiveAgents.Loggers
{
    /// <summary>
    /// Represents a record of data related to a specific turn
    /// </summary>
    public class Turn
    {
        private int _activePlayer; //active performer
        private int _activeDecider; //player that decided who is the next performer 
        private int _nextActivePlayer; //next active player in game
        private double _performence; //utility of active player
        private List<double> _estimatedCompetences = null; //estimated comptences of agents
        private List<bool> _expectedActs = null; //expected acts of players in game

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="numOfPlayers">Total number of players in game</param>
        public Turn(int numOfPlayers)
        {
            _estimatedCompetences = new List<double>(numOfPlayers);
            _expectedActs = new List<bool>(numOfPlayers);
        }

        /// <summary>
        /// Adds a new estimated competence
        /// </summary>
        /// <param name="competence"></param>
        public void addEstimatedCompetence(double competence)
        {
            _estimatedCompetences.Add(competence);
        }

        /// <summary>
        /// Gets the estimated competences list
        /// </summary>
        public List<double> EstimatedCompetences
        {
            get { return _estimatedCompetences; }
        }

        /// <summary>
        /// Adds a new expected act to the list
        /// </summary>
        /// <param name="isExpected">expection of act</param>
        public void addExpectedAct(bool isExpected)
        {
            _expectedActs.Add(isExpected);
        }

        /// <summary>
        /// Gets expected act of specific player
        /// </summary>
        /// <param name="ID">player ID</param>
        /// <returns>expected/not expected</returns>
        public bool getExpectedAct(int ID)
        {
            if (ID < 0 || ID >= _expectedActs.Count)
                throw new IndexOutOfRangeException("Player index is out of bounds");

            return _expectedActs[ID];
        }

        /// <summary>
        /// Gets and Sets the active player in turn
        /// </summary>
        public int ActivePlayer
        {
            get { return _activePlayer; }
            set { _activePlayer = value; }
        }

        /// <summary>
        /// Gets and Sets the next active player in turn
        /// </summary>
        public int NextActivePlayer
        {
            get { return _nextActivePlayer; }
            set { _nextActivePlayer = value; }
        }

        /// <summary>
        /// Gets and Sets the active decider in turn
        /// </summary>
        public int ActiveDecider
        {
            get { return _activeDecider; }
            set { _activeDecider = value; }
        }

        /// <summary>
        /// Gets and Sets the performence of the active player in turn
        /// </summary>
        public double Performence
        {
            get { return Math.Round(_performence, 3); }
            set { _performence = value; }
        }
    }
}
